﻿Imports System.Data.OleDb
Public Class xml_Export
    Dim con As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim da As OleDbDataAdapter
    Dim txt As String
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FolderBrowserDialog1.ShowDialog()
        TextBox1.Text = FolderBrowserDialog1.SelectedPath
    End Sub
    Public Sub filldatagridview(ByVal constr As String)
        con = New OleDbConnection(constr)
        con.Open()
        Me.ShowDialog()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer, j As Integer
        Dim c As Integer
        Dim txtquery As String
        Dim ds As DataSet
        Dim da As OleDbDataAdapter
        While i < Parent1.TreeView1.Nodes.Count
            If Parent1.TreeView1.Nodes(i).Checked = True Then
                txtquery = txtquery & " SELECT "
                c = 0
                While j < Parent1.TreeView1.Nodes(i).Nodes.Count
                    If Parent1.TreeView1.Nodes(i).Nodes(j).Checked = True Then
                        txtquery = txtquery & " " & Parent1.TreeView1.Nodes(i).Nodes(j).Text & ","
                        c = c + 1
                    End If
                    j = j + 1
                End While
                If c = 0 Then
                    txtquery = txtquery & " * "
                Else
                    txtquery = txtquery.Substring(0, txtquery.Length - 1)
                End If
                txtquery = txtquery & " FROM " & Parent1.TreeView1.Nodes(i).Text & vbCrLf
                ds = New DataSet
                da = New OleDbDataAdapter(txtquery, con)
                da.Fill(ds, Parent1.TreeView1.Nodes(i).Text)
                ds.Tables(0).WriteXml(TextBox1.Text & "\" & Parent1.TreeView1.Nodes(i).Text & ".xml")
                j = 0
                txtquery = ""
                Parent1.TreeView1.Nodes(i).Checked = False
            End If
            i = i + 1
        End While
        MsgBox("Exported successfully")
        Me.Close()
    End Sub

    Private Sub xml_Export_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class